/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ui.gui.dialogs.settings;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;

/**
 *
 * @author Leonhart
 */
public class ColorComboBoxRenderer extends DefaultListCellRenderer {

    @Override
    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
        //return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
        
        JPanel panel = new JPanel();
        panel.setLayout(new BorderLayout());
        JPanel carre = new JPanel();
        carre.setOpaque(true);
        Color c = null;
        try {
            c = (Color) Color.class.getField(value.toString().toUpperCase().replaceAll(" ", "_")).get(null);
        } catch (Exception ex) {
            c = Color.CYAN;
        }
        carre.setBackground(value != null ? c : Color.white);
        carre.setMinimumSize(new Dimension(15, 15));
        carre.setPreferredSize(new Dimension(15, 15));
        JLabel render = new JLabel();
        panel.add(render, BorderLayout.CENTER);
        panel.add(carre, BorderLayout.WEST);
        render.setText(value != null ? "  " + value.toString() : "");
        return panel;
    }
}
